package com.lly.songhigh.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lly.songhigh.R;
import com.lly.songhigh.entity.YouLike;

import java.util.List;

/**
 * Created by 李海龙 on 15/11/10.
 */
public class YouLikeListviewAdapter extends BaseAdapter {


    private int size;
    private int zhenSize;
    private Context context;
    private List<YouLike.DataEntity.AuditionListEntity> auditionListEntity;


    public YouLikeListviewAdapter(List<YouLike.DataEntity.AuditionListEntity> auditionListEntity, Context context) {
        this.auditionListEntity = auditionListEntity;
        this.context = context;
    }

    @Override
    public int getCount() {
        return auditionListEntity != null && auditionListEntity.size() > 0 ?auditionListEntity.size() : 0;
    }

    @Override
    public YouLike.DataEntity.AuditionListEntity getItem(int position) {
        return auditionListEntity.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.downloaddialogitem, null);
            holder = new ViewHolder();
            holder.downQuality = (TextView) convertView.findViewById(R.id.download_quality);
            holder.songSize = (TextView) convertView.findViewById(R.id.download_size);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        YouLike.DataEntity.AuditionListEntity entity = getItem(position);
        size = entity.getSize()/1024000;
        zhenSize = entity.getSize() / 10240%100;
        holder.downQuality.setText(entity.getTypeDescription());
        holder.songSize.setText(size + "." + zhenSize + "M");
        return convertView;
    }
    public class ViewHolder{
        private TextView downQuality;
        private TextView songSize;
    }
}
